/*
 * $Id: Constant.java,v 1.6 2003/06/04 18:17:29 znamenacek Exp $
 *
 * Copyright (c) Tomas Znamenacek
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

package net.sf.vofce.guts;

import java.util.Stack;

/**
 * Simple named constant.
 */
public class Constant extends NullaryOperator {

	/** Value represented by this constant. */
	protected double value;

	/**
	 * Creates new named constant with given syntax and value.
	 */
	public Constant(
			String		humanSyntax,
			String		TeXSyntax,
			String		XMLSyntax,
			double		value) {

		this.priority = Integer.MAX_VALUE;

		this.humanSyntax = humanSyntax;
		this.TeXSyntax = TeXSyntax;
		this.XMLSyntax = XMLSyntax;
		this.value = value;
	}

	/**
	 * Returns value represented by this constant.
	 */
	public double getValue() {

		return value;
	}
	
	public double evaluateSubTree() {

		return value;
	}

	/**
	 * Renders constant in simple human notation.
	 */
	public String toString(int parentPriority) {

		return humanSyntax;
	}

	/**
	 * Renders constant in TeX notation.
	 */
	public String toTeX(int parentPriority) {

		return TeXSyntax;
	}

	/**
	 * Renders constant in MathML notation.
	 */
	public String toXML(int parentPriority) {

		return XMLSyntax;
	}

	public String toString() {

		return "<Constant::" + humanSyntax + ">";
	}
	
	public boolean equals(Object o) {

		return (o instanceof Constant) ?
			(((Constant) o).toString().equals(toString())) : false;
	}
}
